Test Series - Data Structure

Test Number 27/115

Q: When an operand is read, which of the following is done?
A. It is placed on to the output
B. It is placed in operator stack
C. It is ignored
D. Operator stack is emptied
Solution: While converting an infix expression to a postfix expression, when an operand is read, it is placed on to the output. When an operator is read, it is placed in the operator stack.
Q: What should be done when a left parenthesis ‘(‘ is encountered?
A. It is ignored
B. It is placed in the output
C. It is placed in the operator stack
D. The contents of the operator stack is emptied
Solution: When a left parenthesis is encountered, it is placed on to the operator stack. When the corresponding right parenthesis is encountered, the stack is popped until the left parenthesis and remove both the parenthesis.
Q: Which of the following is an infix expression?
A. (a+b)*(c+d)
B. ab+c*
C. +ab
D. abc+*
Solution: (a+b)*(c+d) is an infix expression. +ab is a prefix expression and ab+c* is a postfix expression.
Q: What is the time complexity of an infix to postfix conversion algorithm?
A. O(N log N)
B. O(N)
C. O(N2)
D. O(M log N)
Solution: The time complexity of an infix to postfix expression conversion algorithm is mathematically found to be O(N).
Q: What is the postfix expression for the corresponding infix expression?

a+b*c+(d*e)
A. abc*+de*+
B. abc+*de*+
C. a+bc*de+*
D. abc*+(de)*+
Solution: Using the infix to postfix expression conversion algorithm, the corresponding postfix expression is found to be abc*+de*+.
Q: Parentheses are simply ignored in the conversion of infix to postfix expression.
A. True
B. False
C. .....
D. ....
Solution: When a parenthesis is encountered, it is placed on the operator stack. When the corresponding parenthesis is encountered, the stack is popped until the other parenthesis is reached and they are discarded.
Q: It is easier for a computer to process a postfix expression than an infix expression.
A. True
B. False
C. ....
D. ....
Solution: Computers can easily process a postfix expression because a postfix expression keeps track of precedence of operators.
Q: What is the postfix expression for the infix expression?

a-b-c
A. -ab-c
B. ab – c –
C. – -abc
D. -ab-c
Solution: The corresponding postfix expression for the given infix expression is found to be ab-c- and not abc- -.
Q: What is the postfix expression for the following infix expression?

a/b^c-d
A.  abc^/d-
B. ab/cd^-
C. ab/^cd-
D. abcd^/-
Solution: Using the infix to postfix conversion algorithm, the corresponding postfix expression for the infix expression is found to be abc^/d-.
Q: Which of the following statement is incorrect with respect to infix to postfix conversion algorithm?
A. operand is always placed in the output
B. operator is placed in the stack when the stack operator has lower precedence
C. parenthesis are included in the output
D. higher and equal priority operators follow the same condition
Solution: Parentheses are not included in the output. They are placed in the operator stack and then discarded.

You Have Score    /10